home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / WarpQuake / Src / sys_amiga.c < prev    next >
C/C++ Source or Header  |  2000-05-22  |  6KB  |  319 lines

  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <signal.h>
  24.  
  25. #include <utility/tagitem.h>
  26. #include <exec/exec.h>
  27. #include <exec/types.h>
  28. #include <dos/exall.h>
  29. #include <dos/dos.h>
  30. #include <devices/timer.h>
  31. #include <powerup/ppcproto/dos.h>
  32. #include <powerup/ppcproto/exec.h>
  33. #include <powerpc/powerpc.h>
  34. #include <powerpc/powerpc_protos.h>
  35.  
  36. #include "quakedef.h"
  37. #include "errno.h"
  38.  
  39. qboolean isDedicated = FALSE;
  40. static int bat = false;
  41.  
  42. extern struct Mode_Screen *msptr;
  43. extern const char amigaversion[];
  44.  
  45. void Sys_Shutdown (void);
  46.  
  47. /*
  48. ===============================================================================
  49.  
  50. FILE IO
  51.  
  52. ===============================================================================
  53. */
  54.  
  55. #define    MAX_HANDLES        10
  56. BPTR sys_handles[MAX_HANDLES];
  57.  
  58. int findhandle (void)
  59. {
  60.     int        i;
  61.     
  62.     for (i=1 ; i<MAX_HANDLES ; i++)
  63.         if (!sys_handles[i])
  64.             return i;
  65.     Sys_Error ("out of handles");
  66.     return -1;
  67. }
  68.  
  69. /*
  70. ================
  71. filelength
  72. ================
  73. */
  74. int filelength (BPTR f)
  75. {
  76.     LONG        pos;
  77.     LONG        end;
  78.  
  79.     pos = Seek (f, 0, OFFSET_END);
  80.     end = Seek (f, pos, OFFSET_BEGINNING);
  81.  
  82.     return (int) end;
  83. }
  84.  
  85. int Sys_FileOpenRead (char *path, int *hndl)
  86. {
  87.     BPTR f;
  88.     int        i;
  89.     
  90.     i = findhandle ();
  91.  
  92. //    printf ("Opening '%s' for read\n", path);
  93.     f = Open(path, MODE_OLDFILE);
  94.     if (!f)
  95.     {
  96.         *hndl = -1;
  97.         return -1;
  98.     }
  99.     sys_handles[i] = f;
  100.     *hndl = i;
  101.     
  102.     return filelength(f);
  103. }
  104.  
  105. int Sys_FileOpenWrite (char *path)
  106. {
  107.     BPTR f;
  108.     int        i;
  109.     
  110.     i = findhandle ();
  111.  
  112. //    printf ("Opening '%s' for write\n", path);
  113.     f = Open(path, MODE_NEWFILE);
  114.     if (!f)
  115.         Sys_Error ("Error opening %s: %s", path,strerror(errno));
  116.     sys_handles[i] = f;
  117.     
  118.     return i;
  119. }
  120.  
  121. void Sys_FileClose (int handle)
  122. {
  123. //    printf("Sys_FileClose() %i\n", handle);
  124.     Close (sys_handles[handle]);
  125.     sys_handles[handle] = NULL;
  126. }
  127.  
  128. void Sys_FileSeek (int handle, int position)
  129. {
  130.     /* printf ("%d: Seeking to %d\n", handle, position); */
  131.     if (Seek (sys_handles[handle], position, OFFSET_BEGINNING) == -1)
  132.         Sys_Error ("Error in Seek()");
  133. }
  134.  
  135. int Sys_FileRead (int handle, void *dest, int count)
  136. {
  137.     /* printf ("%d: Reading %d to %08x\n", handle, count, dest); */
  138.     return (int)Read (sys_handles[handle], dest, count);
  139. }
  140.  
  141. int Sys_FileWrite (int handle, void *data, int count)
  142. {
  143.     return (int)Write (sys_handles[handle], data, count);
  144. }
  145.  
  146. int    Sys_FileTime (char *path)
  147. {
  148.     BPTR f;
  149.     
  150.     f = Open(path, MODE_OLDFILE);
  151.     if (f)
  152.     {
  153.         Close(f);
  154.         return 1;
  155.     }
  156.     
  157.     return -1;
  158. }
  159.  
  160. void Sys_mkdir (char *path)
  161. {
  162. }
  163.  
  164.  
  165. /*
  166. ===============================================================================
  167.  
  168. SYSTEM IO
  169.  
  170. ===============================================================================
  171. */
  172.  
  173. void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
  174. {
  175. }
  176.  
  177.  
  178. void Sys_DebugLog(char *file, char *fmt, ...)
  179. {
  180. }
  181.  
  182. void Sys_Error (char *error, ...)
  183. {
  184.     va_list        argptr;
  185.  
  186.     printf ("Sys_Error: ");    
  187.     va_start (argptr,error);
  188.     vprintf (error,argptr);
  189.     va_end (argptr);
  190.     printf ("\n");
  191.  
  192.     Host_Shutdown();
  193.     Sys_Shutdown();
  194.     exit (20);
  195. }
  196.  
  197. void Sys_Printf (char *fmt, ...)
  198. {
  199.     va_list        argptr;
  200.     
  201.     va_start (argptr,fmt);
  202.     if (!con_initialized)
  203.       vprintf (fmt,argptr);
  204.     va_end (argptr);
  205. }
  206.  
  207. void Sys_Quit (void)
  208. {
  209.     Host_Shutdown();
  210.     Sys_Shutdown();
  211.     exit (0);
  212. }
  213.  
  214. void Sys_Shutdown (void)
  215. {
  216.     int i;
  217.  
  218.     for (i=1; i<MAX_HANDLES ; i++)
  219.     {
  220.         if (sys_handles[i])
  221.             Sys_FileClose (i);
  222.     }
  223.  
  224.     if (bat)
  225.         ChangeMMU (CHMMU_STANDARD);
  226. }
  227.  
  228. double Sys_FloatTime (void)
  229. {
  230.     struct timeval tv;
  231.  
  232.     GetSysTimePPC (&tv);
  233.   return tv.tv_secs + tv.tv_micro / 1000000.0;
  234. }
  235.  
  236. char *Sys_ConsoleInput (void)
  237. {
  238.     return NULL;
  239. }
  240.  
  241. void Sys_Sleep (void)
  242. {
  243. }
  244.  
  245. /*
  246. void Sys_SendKeyEvents (void)
  247. {
  248. }
  249. */
  250.  
  251. void Sys_HighFPPrecision (void)
  252. {
  253. }
  254.  
  255. void Sys_LowFPPrecision (void)
  256. {
  257. }
  258.  
  259. //=============================================================================
  260.  
  261. int main (int argc, char **argv)
  262. {
  263.   int j;
  264.   double time, oldtime, newtime;
  265.   quakeparms_t parms;
  266.  
  267.     msptr = NULL;
  268.  
  269.     signal (SIGINT, (void *)Sys_Quit);
  270.     signal (SIGTERM, (void *)Sys_Quit);
  271.  
  272.     printf("%s\n\n", &amigaversion[6]);
  273.  
  274.   memset (&parms, 0, sizeof(parms));
  275.  
  276.   COM_InitArgv (argc, argv);
  277.  
  278.   parms.memsize = 8*1024*1024;
  279.   j = COM_CheckParm("-mem");
  280.   if (j)
  281.     parms.memsize = (int) (Q_atof(com_argv[j+1]) * 1024 * 1024);
  282.   if ((parms.membase = malloc (parms.memsize)) == NULL)
  283.     Sys_Error ("Can't allocate %d bytes", parms.memsize);
  284.   parms.basedir = "PROGDIR:";
  285.   parms.cachedir = "";
  286.  
  287.   parms.argc = com_argc;
  288.   parms.argv = com_argv;
  289.  
  290.     bat = COM_CheckParm("-bat");
  291.     if (bat)
  292.         ChangeMMU (CHMMU_BAT);
  293.  
  294. //    printf ("Host_Init\n");
  295.     Host_Init (&parms);
  296.  
  297.     Host_Frame (0.1);
  298.  
  299.     oldtime = Sys_FloatTime ();
  300.     while (1)
  301.     {
  302.         newtime = Sys_FloatTime ();
  303.  
  304.         time = newtime - oldtime;
  305.  
  306. //        if (time < 0.0)
  307. //            printf ("Negative time = %f!!\n", time);
  308.  
  309. //        if (cls.state == ca_dedicated && (time<sys_ticrate.value))
  310. //            continue;
  311.  
  312.         Host_Frame ((float)time);
  313.  
  314.         oldtime = newtime;
  315.     }
  316. }
  317.  
  318. /**********************************************************************/
  319.